// MyMenu.cpp : implementation file
//

#include "stdafx.h"
#include "MyMenu.h"
#include "AnsiEditor.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyMenu

CMyMenu::CMyMenu()
{
}

CMyMenu::~CMyMenu()
{
}


/////////////////////////////////////////////////////////////////////////////
// CMyMenu message handlers

BOOL CMyMenu::AppendMenu(UINT nIDNewItem, LPCTSTR lpszNewItem/* = NULL */)
{
	if(lpszNewItem)
	{
		return CMenu::AppendMenu(MF_STRING, nIDNewItem, lpszNewItem);
	}
	CString sMenuText;
	sMenuText.LoadString(nIDNewItem);
	return CMenu::AppendMenu(MF_STRING, nIDNewItem, sMenuText);
}

void CMyMenu::AppendSeparator()
{
	CMenu::AppendMenu(MF_SEPARATOR, 0, (LPCTSTR)NULL);
}

void CMyMenu::EnableMenuItem(UINT nIDEnableItem, BOOL bEnabled)
{
	UINT nEnable = MF_BYCOMMAND;
	if(bEnabled)
	{
		nEnable |= MF_ENABLED;
	}
	else
	{
		nEnable |= (MF_DISABLED|MF_GRAYED);
	}
	CMenu::EnableMenuItem(nIDEnableItem, nEnable);
}

BOOL CMyMenu::LoadMenu(UINT nIDResource)
{
	BOOL bResult = CMenu::LoadMenu(nIDResource);
	gpApp->m_mui.UpdateMenu(this);
	return bResult;
}

BOOL CMyMenu::TrackPopupMenuEx(UINT fuFlags, int x, int y, CWnd *pWnd, LPTPMPARAMS lptpm/* = NULL */)
{
	gpApp->m_mui.UpdateMenu(this);
	return ::TrackPopupMenuEx(m_hMenu, fuFlags, x, y, pWnd->GetSafeHwnd(), lptpm);
}

CMyMenu* CMyMenu::GetSubMenu(int nPos) const
{
	return (CMyMenu*)CMenu::GetSubMenu(nPos);
}

BOOL CMyMenu::TrackPopupMenu(UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect/* = 0 */)
{
	gpApp->m_mui.UpdateMenu(this);
	return CMenu::TrackPopupMenu(nFlags, x, y, pWnd, lpRect);
}